/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package im.resources.monitors;

/**
 *
 * @author brownstone
 */
public class EnergyMonitor {

    private float energy,value;
	boolean plugged;
	public EnergyMonitor() {
		plugged = false;
		energy = (float)(Math.random());
	}

	public float check(){

		if ( ((int)(Math.random()*1000) % 100) < 2) {
			plugged = !plugged;
		}

		if (plugged == false) {
			energy -= 0.005f;
			value = energy;
		}
		else {
			energy += 0.005f;
			if (energy>1)
				energy = 1;
			value = 1;
		}

		if (energy<0) {
			System.out.println("Batteria esaurita ! Il nodo si sta spegnendo.");
			System.exit(0);
		}
	//	System.out.println("Valore energia = "+energy+" valore inviato = "+value+", plugged = "+plugged);
		return energy;
	}
}
